#include "rewardorpunish.h"
#include "ui_rewardorpunish.h"
#include"qualifydocu.h"
#include<QString>
#include<QDebug>
#include<QMessageBox>
rewardorpunish::rewardorpunish(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::rewardorpunish)
{
    ui->setupUi(this);
    connect(ui->cancel,SIGNAL(clicked(bool)),this,SLOT(close()));
    connect(ui->confirm,SIGNAL(clicked(bool)),this,SLOT(react()));
    connect(ui->confirm,SIGNAL(clicked(bool)),parent,SLOT(showRewardInfo()));
}

rewardorpunish::~rewardorpunish()
{
    delete ui;
}
void rewardorpunish::react(){
    //sqlconnect(db);
    QString rdate=ui->rewarddate->text();
    QString rname=ui->rewardEdit->text();
    if(rdate.count()==0||rname.count()==0){
        QMessageBox::information(this,"提示信息","输入有空项！");
        return;
        }
    //qDebug()<<rdate;
    QSqlQuery qu("select * FROM `Reward` WHERE RewardTime='"+rdate+"' and RewardName='"+rname+"' and IDNum='"+ID+"'");
    if(qu.next())
    {
        QMessageBox::information(this,"提示信息","该奖励已存在，不可重复添加！");
       return;
    }


    QSqlQuery query;
    QString sql1="INSERT INTO Reward(RewardTime,RewardName,IDNum)VALUES('"+rdate+"','"+rname+"','"+ID+"')";
    bool ok1=query.exec(sql1);
    //qDebug()<<ok;
    if(ok1){
        QMessageBox::information(this,"提示信息","成功插入!");
    }
    this->close();
}
void rewardorpunish::reciveID(QString s){
    ID=s;
}
